package com.iweb.education.student.Service;

import com.iweb.education.student.Dao.StudentDao;
import com.iweb.education.student.Dao.StudentDaoImpl;
import com.iweb.education.student.Model.Student;

import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

public class StudentServiceImpl implements StudentService{
    StudentDao studentDao=new StudentDaoImpl();
    @Override
    public boolean isLogin(Integer sid, String spassword, HttpSession session) {
        Student student=studentDao.selectBySidSpassword(sid,spassword);
        if (student!=null){
            session.setAttribute("student",student);
            return true;
        }else {
            return false;
        }
    }
    @Override
    public Map  <String, Object> showPersonalInfo(Integer sid) {
        return studentDao.showPersonalInfo(sid);
    }
    @Override
    public List<Map<String, Object>> getGrades(Integer sid) {
        return studentDao.getGrades(sid);
    }
    @Override
    public List<Map<String, Object>> getCourseList() {
        return studentDao.getCourseList();
    }

    @Override
    public boolean selectCourse(Integer sid, Integer cid) {
        if (studentDao.selectCourse(sid, cid)) {
            return studentDao.updateCourseNumber(cid, false);
        }
        return false;
    }

    @Override
    public boolean dropCourse(Integer sid, Integer cid) {
        if (studentDao.dropCourse(sid, cid)) {
            return studentDao.updateCourseNumber(cid, true);
        }
        return false;
    }

    @Override
    public boolean isSelectedCourse(Integer sid, Integer cid) {
        return studentDao.isSelectedCourse(sid, cid);
    }
}
